<?php
class PresscenterModule extends fvModule {

	function __construct () {
	    $moduleName = strtolower(substr(__CLASS__, 0, -6));
	    parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"), 
	                        fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"), 
	                        fvSite::$Layoult);
	}
	
	function showIndex($params) {
		fvSite::$Layoult->setTitle(fvSite::$Layoult->getTitle().' > Пресс-центр');
		$News = PresscenterManager::getInstance()->getAll("type='news' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
		$Articles = PresscenterManager::getInstance()->getAll("type='article' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
		$Smi = PresscenterManager::getInstance()->getAll("type='smi' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
	    $this->__assign(array("news" => $News, "articles" => $Articles, "smi" => $Smi));
        return $this->__display("presscenter_index.tpl");
	}
	
	function showOne($params) {
	    $request = fvRequest::getInstance();
        if (!$Presscenter = PresscenterManager::getInstance()->getByPk($request->getRequestParameter('id'))) {
            $Presscenter = new Presscenter();
            
        }
        $this->__assign(array(
            'Presscenter' => $Presscenter,
        ));
        return $this->__display('presscenter_one.tpl');
	}
	
	function showType($params) {
	    $request = fvRequest::getInstance();
	    if (in_array($request->getRequestParameter('type'), array("news", "article", "smi"))){
	    	$pager = new fvPager(PresscenterManager::getInstance());
        	$Presscenter = $pager->paginate("type='".$request->getRequestParameter('type')."' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC");
	    }
	    else{
	    }
        $this->__assign(array(
            'Presscenter' => $Presscenter,
        	"type" => $request->getRequestParameter('type')
        ));
        return $this->__display('presscenter_list.tpl');
	}
	
	function showNewsblock() {
		$request = fvRequest::getInstance();
		$Presscenter = PresscenterManager::getInstance()->getAll("type='news' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
	    $this->__assign('Presscenter', $Presscenter);
	    return $this->__display("presscenter_newsblock.tpl");
	}
	
	function showArticlesblock() {
		$request = fvRequest::getInstance();
		$Presscenter = PresscenterManager::getInstance()->getAll("type='article' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
	    $this->__assign('Presscenter', $Presscenter);
	    return $this->__display("presscenter_articlesblock.tpl");
	}
	
	function showPressblock() {
		$request = fvRequest::getInstance();
		$Presscenter = PresscenterManager::getInstance()->getAll("type='smi' and lang='".fvSite::$fvSession->get("lang")."'", "create_date DESC", "0,3");
	    $this->__assign('Presscenter', $Presscenter);
	    return $this->__display("presscenter_pressblock.tpl");
	}
	
}
?>